package cn.attackme.myuploader.test;

import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import java.io.*;

public class filetest {
    public static boolean copyFile(String path,String newpath) {
        try {
            java.io.File f = new java.io.File(path);
            if (f.isFile() && f.exists()) {
                FileInputStream in = new FileInputStream(f);
                FileOutputStream out = new FileOutputStream(new java.io.File(newpath));
                byte[] buffer = new byte[1024];
                int len = -1;
                while ((len = in.read(buffer)) != -1) {
                    out.write(buffer, 0, len);
                }
                in.close();
                out.close();
                System.out.println("拷贝文件成功！ 程序退出");
                return true;
            } else {
                System.out.println("文件不存在或输入的不是文件是目录！请重新输入");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }
    public static void main(String[] args) throws IOException {
        String path = "C:\\Users\\admin\\Documents\\WeChat Files\\wxid_o0pgc0npewxa22\\FileStorage\\File\\2021-05\\电子发票识别结果.xls";
        String newpath = "C:\\Users\\admin\\Desktop\\invoice\\电子发票识别结果.xls";
        //copyFile(path,newpath);
        FileInputStream excelFileInputStream = new FileInputStream(path);
        HSSFWorkbook workbook = new HSSFWorkbook (excelFileInputStream);
        excelFileInputStream.close();
        HSSFSheet sheet = workbook.getSheetAt(0);
        HSSFRow row = sheet.createRow(12);
        row.createCell(0).setCellValue("666");
        System.out.println(row.getCell(0).getStringCellValue());
        //FileOutputStream output_file =new FileOutputStream(new File("C:\\Users\\admin\\Desktop\\invoice\\电子发票识别结果3.xls"));
        //workbook.write(output_file);
        workbook.close();
        //output_file.close();
    }
}
